package org.small.shop.phone.api.config.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.small.shop.phone.api.utils.AppConstantUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * 系统登录拦截器类
 * 
 * @ClassName: LoginInterceptor
 * @Description:
 * @author LQY(廖先生)
 * @date 2017年12月29日 下午12:54:25
 *
 */
@Component
public class LoginInterceptor implements HandlerInterceptor {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {

		if (!StringUtils.isEmpty(AppConstantUtils.getAppId(request))) {
			return true;
		}
		response.sendRedirect(request.getContextPath() + "/isNotLogin");
		return false;

	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {

	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {

	}

}